package com.reggie.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author 早睡蛋
 * @Date 2022/7/22 17:30:08
 * @Desc:
 * swagger2配置类
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
public class Swagger2Config {

    private ApiInfo employeeApiInfo(){
        return new ApiInfoBuilder()
                .title("员工-API文档")
                .description("本文档描述了后台相关接口定义")
                .version("1.0")
                .contact(new Contact("author", "xxx", "mail@xx.com"))
                .build();
    }
    @Bean
    public Docket testApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("员工API")
                .apiInfo(employeeApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/employee/.*")))
                .build();
    }

    private ApiInfo categoryApiInfo(){
        return new ApiInfoBuilder()
                .title("菜单分类-API文档")
                .description("本文档描述了后台相关接口定义")
                .version("1.0")
                .contact(new Contact("author", "xxx", "mail@xx.com"))
                .build();
    }
    @Bean
    public Docket categoryApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("菜单分类API")
                .apiInfo(categoryApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/category/.*")))
                .build();
    }

    private ApiInfo uploadApiInfo(){
        return new ApiInfoBuilder()
                .title("上传-API文档")
                .description("本文档描述了后台相关接口定义")
                .version("1.0")
                .contact(new Contact("author", "xxx", "mail@xx.com"))
                .build();
    }
    @Bean
    public Docket uploadApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("上传API")
                .apiInfo(uploadApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/common/.*")))
                .build();
    }

}
